

const _url = 'https://ht.mogooo.cn//api';
//ajax请求?
wx.ajax = function (e, data = [], method = 'get', c = false) {
  return new Promise(function (a, b) {
    if (c && !wx.getStorageSync('uid')) {
      wx.navigateTo({
        url: '/pages/userauthorization/index',
      })
      return false
    }
    // wx.showLoading({
    //   title: '加载中',
    //   mask:true
    // })

    var _request_data = {
      url: _url + e,
      method: method,
      data: data,
      header: {
        'content-type': 'application/json',
        'uid': wx.getStorageSync('uid')
      },
      success(res) {
        wx.hideLoading()
        if(!res.data.user_info && c){
          // 清除所有的用户信息仇重新授权
          wx.clearStorageSync()
          // 用户身份不存在的时候
          wx.navigateTo({
            url: '/pages/userauthorization/index',
          })
          return false
        }
        if (res.data.status_code == '200') {
          a(res.data)
        } else {
          b(res)
          wx.showToast({
            title: res.data.message,
            icon: 'none'
          })
        }
      },
      fail(res) {
        wx.hideLoading()
        b(res)
      }
    }
    wx.request(_request_data)
  })
}
// 图片上传
wx.up_img = function (files, fn) {
  console.log(files)
  files.forEach(function (a, b) {
    wx.uploadFile({
      url: _url + '/uploads/img',
      filePath: a.path,
      header: {

      },
      name: 'files',
      formData: {
        'user': 'test'
      },
      success(e) {
        fn(JSON.parse(e.data))
      },
      fail(e) {
        console.log(e)
      }
    })
  })
}


wx.ajax('/is_examine').then(res=>{
    wx.bug=res.examine
})
